import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../../../widget/price_Widget/index.dart';
import '../models/payments_model.dart';

class PaymentsGoodsWidget extends ConsumerStatefulWidget {
  final List<PaymentsGoodsModel> goods;

  const PaymentsGoodsWidget({super.key, required this.goods});

  @override
  _PaymentsGoodsWidgetState createState() => _PaymentsGoodsWidgetState();
}

class _PaymentsGoodsWidgetState extends ConsumerState<PaymentsGoodsWidget> {
  @override
  Widget build(BuildContext context) {
    return ListView.separated(
      shrinkWrap: true,
      physics: const NeverScrollableScrollPhysics(),
      itemBuilder: (BuildContext context, int index) {
        return Container(
          padding: const EdgeInsets.all(10),
          width: double.infinity,
          decoration: BoxDecoration(borderRadius: BorderRadius.circular(10), color: Colors.white),
          child: Row(
            children: [
              Image.network(
                widget.goods[index].picture,
                width: 100,
                height: 100,
              ),
              const SizedBox(width: 8),
              Expanded(
                child: SizedBox(
                  height: 100,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        widget.goods[index].name,
                        style: const TextStyle(fontSize: 16, color: Colors.black),
                        maxLines: 2,
                        overflow: TextOverflow.ellipsis,
                      ),
                      Container(
                        padding: const EdgeInsets.all(2),
                        decoration: BoxDecoration(
                          borderRadius: const BorderRadius.all(Radius.circular(4)),
                          color: Colors.grey[100],
                        ),
                        child: Text.rich(
                          TextSpan(
                            text: widget.goods[index].attrsText,
                            style: const TextStyle(fontSize: 12),
                          ),
                        ),
                      ),
                      PriceWidget(price: widget.goods[index].price),
                    ],
                  ),
                ),
              ),
              const SizedBox(width: 18),
              Row(
                children: [
                  const Icon(
                    Icons.close,
                    color: Colors.grey,
                    size: 12,
                  ),
                  Text(
                    "${widget.goods[index].count}",
                    style: const TextStyle(
                      color: Colors.grey,
                    ),
                  ),
                ],
              )
            ],
          ),
        );
      },
      separatorBuilder: (BuildContext context, int index) {
        return const SizedBox(height: 10);
      },
      itemCount: widget.goods.length,
    );
  }
}
